package org.jackysoft.opensymphony.workflow.util;

import java.util.Map;

import org.jackysoft.entity.Variable;
import org.jackysoft.entity.WorkflowEntry;
import org.jackysoft.opensymphony.workflow.Condition;
import org.jackysoft.opensymphony.workflow.WorkflowException;
import org.jackysoft.service.VariableService;
import org.jackysoft.service.WorkflowService;


/**
 * <DD> 这个类主要用来检查会签到达后是否同签的要求
 * <DD>
 *
 *   &lt;condition type="class"&gt;<br>
       &lt;arg name="class.name"&gt;
           com.opensymphony.workflow.util.TeamJoinCondition
       &lt;/arg&gt;<br/>
     &lt;/condition&gt;
     
 * <DD>
 * 
 * */
public class TeamJoinCondition implements Condition {
	String status = "Finished";
	@Override
	public boolean passesCondition(Map transientVars, Map args,VariableService vservice)
			throws WorkflowException {
		//TODO  从持久化变量里找到 会签所需要汇聚的步骤
		
		WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
		String teamstep = null;
		Variable wv = vservice.get(entry.getId(), "teamstep");
		if(wv==null) throw new WorkflowException("会签步骤异常,请检查会签节点");
		teamstep = wv.getValue();
		String[] steps = teamstep.split("\\,");
		WorkflowService store = (WorkflowService) transientVars.get("store");
	    for(String s:steps){
	    	Integer sid = Integer.parseInt(s);
	    	if(!store.stepInStatus(sid, status)) return false;
	    }
		return true;
	}

}
